////
//// Created by lfm on 2025/3/3.
////
#include <iostream>
using namespace std;
class Person
{
public:
    Person(int age)
    {
        m_Age = new int(age);
    }
    //浅拷贝导致的内存重复释放
    ~Person()
    {
        if (m_Age != NULL)
        {
            delete m_Age;
            m_Age = NULL;
        }
    }

    Person& operator=(Person& p)
    {
        if (m_Age != NULL)
        {
            delete m_Age;
            m_Age = NULL;
        }
        m_Age = new int (*p.m_Age);
        return *this;
    }
    int *m_Age;
};
void test01()
{
    Person p1(19);

    Person p2(20);

    Person p3(30);
    p1 = p2 = p3;
    cout << "p1 age = " << *p1.m_Age << endl;

    cout << "p2 age = " << *p2.m_Age << endl;

    cout << "p3 age = " << *p3.m_Age << endl;
}
int main()
{
    test01();
    system("pause");
    return 0;
}
